<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Recos</title>
    <meta name="description" content="Recos">
    <meta name="keywords" content="Recos">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/sidebar.css">
    <link href="../plugins/quill/quill.snow.css" rel="stylesheet">
    <link href="../plugins/quill/quill.bubble.css" rel="stylesheet">
    <link href="../plugins/quill/quill.core.css" rel="stylesheet">
    <script src="../plugins/quill/quill.js"></script>

</head>
<body class="hold-transition">

<div id="app" class="app">
<!--    <iframe src="sidebar.html" ></iframe>-->
    <!-- 使用JavaScript加载侧边栏内容 -->
    <div id="sidebar-container"></div>

    <!-- 其他内容 -->
    <script>
        // 使用JavaScript加载侧边栏内容
        const sidebarContainer = document.getElementById("sidebar-container");
        const xhr = new XMLHttpRequest();
        xhr.open("GET", "sidebar.html", true);
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                sidebarContainer.innerHTML = xhr.responseText;
            }
        };
        xhr.send();
    </script>


    <div id="page-container">

        <div class="content-header">
            <h1 aria-label="center">Recos-绑定配置管理</h1>
            <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                <el-breadcrumb-item :to="{ path: '/' }"></el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="app-container">
            <div class="box">
                <div><h3 aria-label="center">绑定配置</h3></div>

                <el-table  size="small" current-row-key="id"
                           :data="dataList" stripe highlight-current-row
                           :cell-style="cellStyle"
                           @selection-change="handleSelectionChange">
                    <el-table-column
                            type = 'selection'
                            label="是否选中"
                            width="45"
                            prop="id">
                    </el-table-column>
                    <el-table-column label="服务名" align="center" prop="appName" ></el-table-column>
                    <el-table-column label="服务ip" align="center" prop="remoteHost" ></el-table-column>
                    <el-table-column label="服务端口" align="center" prop="serverport" ></el-table-column>
                    <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button slot="reference" type="primary" size="mini" prop="href"  @click="gotoHref(scope.row)">编辑配置</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div class="pagination-container">
                    <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                    </el-pagination>
                </div>


            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/elementui/index.js"></script>


<script src="../plugins/quill/vue-quill-editor.js"></script>
<script src="../js/token.js"></script>
<script>


    var vue = new Vue({
        el: '#app',
        data:{
            textarea: '',
            appNameInput:'',
            dataIdInput:'',
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:5,//每页显示的记录数
                total:0,//总记录数
                queryString:null,//查询条件
                sId:0//学校id
            },

            dataList: [],
            redisServerPath: "/redisServer",
            recosServerPath: "/recos/conf",
            recosConfigInfoPath: "/recos/configinfo"
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            if (!getToken() || getToken()==''){
                window.location.href="./login.html"

            }
            this.findPage();
        },
        methods: {
            findPage() {
                axios.post(this.recosServerPath+"/list",this.pagination,getAxiosConfig()).then((res)=>{
                    if (res.data.success){
                        this.dataList = res.data.data.list;
                        this.pagination.total = res.data.data.total;
                    }else if (res.data.code==-555){
                        window.location.href="./login.html";
                    }
                }).catch((error)=>{
                    if (error == "Error: Request failed with status code 403"){
                        this.$message.error("无操作权限");
                    }
                });

            },

            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            gotoHref(row){
                // console.log(row.appName +" ....===><")
                //跳转到服务详情页
                window.open("/pages/config_details.html?appName="+row.appName+"&token="+getToken());
            },


        }
    });
    Vue.use(window.VueQuillEditor);
</script>
<style>
    .item {
        margin-top: 10px;
        margin-right: 40px;
    }
</style>
</html>